<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <!-- <el-form-item label="原平台" prop="platform">
        <el-select
          v-model="queryParams.platform"
          class="form-sty"
          @keyup.enter="handleQuery"
          clearable
          placeholder="请选择平台"
        >
          <el-option
            v-for="dict in dict.type.sys_event_platform"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item> -->
      <!-- <el-form-item label="原事件类型" prop="originalType" label-width="120px">
        <el-select
          v-model="queryParams.originalType"
          placeholder="请选择原事件类型名称"
          style="width: 100%"
          @keyup.enter="handleQuery"
          clearable
        >
          <el-option
            v-for="item in options"
            :key="item.bigType"
            :label="item.bigType"
            :value="item.bigType"
          />
        </el-select>
      </el-form-item> -->
      <el-form-item label="现类型" prop="typeName">
        <el-input
          v-model="queryParams.typeName"
          placeholder="请输入现类型名称"
          clearable
          size="small"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择类型状态"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="dict in dict.type.sys_normal_disable"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          >导出</el-button
        >
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="typeRelationList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" width="100">
        <template v-slot="scope">
          <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="原平台" align="center" prop="platform" />
      <el-table-column label="原事件类型" align="center" prop="originalType" sortable>
        <template v-slot="scope">
          <div>{{ scope.row.originalType }}</div>
        </template>
      </el-table-column>
      <el-table-column label="现类型" align="center" prop="typeName" sortable>
        <template v-slot="scope">
          <div>{{ scope.row.typeName }}</div>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template v-slot="scope">
          <el-switch
            v-model="scope.row.status"
            active-value="0"
            inactive-value="1"
            @change="handleStatusChange(scope.row)"
          >
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template v-slot="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            >修改</el-button
          >
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
      <template v-slot:empty>
        <el-empty :image-size="300"></el-empty>
      </template>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改事件类型关联表对话框 -->
    <el-dialog :title="title" v-model:visible="open" width="650px" append-to-body>
      <el-form ref="form" :model="form" label-width="100px">
        <!-- <el-form-item label="原平台" prop="platform">
          <el-select
            v-model="form.platform"
            class="form-sty"
            clearable
            placeholder="请选择"
            style="width: 100%"
          >
            <el-option
              v-for="dict in dict.type.sys_event_platform"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item> -->
        <!-- <el-form-item label="原事件类型" prop="originalType">
          <el-select
            v-model="form.originalType"
            placeholder="请选择原事件类型名称"
            style="width: 100%"
          >
            <el-option
              v-for="item in options"
              :key="item.bigType"
              :label="item.bigType"
              :value="item.bigType"
            />
          </el-select>
        </el-form-item> -->
        <el-form-item label="现类型" prop="typeName">
          <el-input v-model="form.typeName" placeholder="请输入现类型名称" />
        </el-form-item>
        <!-- <el-form-item label="类型状态：">
          <el-radio-group v-model="form.status">
            <el-radio
              v-for="dict in dict.type.sys_normal_disable"
              :key="dict.value"
              :label="dict.value"
              >{{ dict.label }}</el-radio
            >
          </el-radio-group>
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script setup>
  // import {
  //   listTypeRelation,
  //   getTypeRelation,
  //   delTypeRelation,
  //   addTypeRelation,
  //   updateTypeRelation,
  //   platformType
  // } from '@/api/event/typeRelation'
  const dicts = ref(['sys_normal_disable', 'sys_event_platform']);
  const ids = ref([]);
  const open = ref(false);
  const loading = ref(false);
  const single = ref(true);
  const multiple = ref(true);
  const showSearch = ref(true);
  const title = ref('');
  const predefineColors = ref([
    'rgba(255, 0, 0, 1)',
    'rgba(255, 165, 0, 1)',
    'rgba(255, 255, 0, 1)',
    'rgba(0, 0, 255, 1)',
  ]);
  const total = ref(0);
  const typeRelationList = ref([
    {
      searchValue: null,
      gridId: null,
      gridName: null,
      gridDept: null,
      gridIds: null,
      gridIdsString: null,
      createBy: null,
      createTime: '2024-02-27 15:22:18',
      updateBy: null,
      updateTime: null,
      remark: null,
      poi: null,
      delFlag: null,
      params: {},
      id: 8,
      typeName: '城市管理',
      originalType: '事件',
      platform: 'szhcg',
      status: '0',
    },
    {
      searchValue: null,
      gridId: null,
      gridName: null,
      gridDept: null,
      gridIds: null,
      gridIdsString: null,
      createBy: null,
      createTime: '2024-02-27 15:22:18',
      updateBy: null,
      updateTime: null,
      remark: null,
      poi: null,
      delFlag: null,
      params: {},
      id: 9,
      typeName: '城市管理',
      originalType: '部件',
      platform: 'szhcg',
      status: '0',
    },
    {
      searchValue: null,
      gridId: null,
      gridName: null,
      gridDept: null,
      gridIds: null,
      gridIdsString: null,
      createBy: null,
      createTime: '2024-02-27 15:22:18',
      updateBy: null,
      updateTime: null,
      remark: null,
      poi: null,
      delFlag: null,
      params: {},
      id: 10,
      typeName: '综合执法',
      originalType: '专项普查',
      platform: 'szhcg',
      status: '0',
    },
    {
      searchValue: null,
      gridId: null,
      gridName: null,
      gridDept: null,
      gridIds: null,
      gridIdsString: null,
      createBy: null,
      createTime: '2024-02-27 15:22:18',
      updateBy: null,
      updateTime: null,
      remark: null,
      poi: null,
      delFlag: null,
      params: {},
      id: 11,
      typeName: '综合执法',
      originalType: '综合督查',
      platform: 'szhcg',
      status: '0',
    },
    {
      searchValue: null,
      gridId: null,
      gridName: null,
      gridDept: null,
      gridIds: null,
      gridIdsString: null,
      createBy: null,
      createTime: '2024-02-27 15:22:18',
      updateBy: null,
      updateTime: null,
      remark: null,
      poi: null,
      delFlag: null,
      params: {},
      id: 12,
      typeName: '综合执法',
      originalType: '园林绿化',
      platform: 'szhcg',
      status: '0',
    },
    {
      searchValue: null,
      gridId: null,
      gridName: null,
      gridDept: null,
      gridIds: null,
      gridIdsString: null,
      createBy: null,
      createTime: '2024-02-27 15:22:18',
      updateBy: null,
      updateTime: null,
      remark: null,
      poi: null,
      delFlag: null,
      params: {},
      id: 13,
      typeName: '城市管理',
      originalType: '创卫巡查',
      platform: 'szhcg',
      status: '0',
    },
    {
      searchValue: null,
      gridId: null,
      gridName: null,
      gridDept: null,
      gridIds: null,
      gridIdsString: null,
      createBy: null,
      createTime: '2024-02-27 15:22:18',
      updateBy: null,
      updateTime: null,
      remark: null,
      poi: null,
      delFlag: null,
      params: {},
      id: 14,
      typeName: '城市管理',
      originalType: '环保类',
      platform: 'szhcg',
      status: '0',
    },
    {
      searchValue: null,
      gridId: null,
      gridName: null,
      gridDept: null,
      gridIds: null,
      gridIdsString: null,
      createBy: null,
      createTime: '2024-02-27 15:22:18',
      updateBy: null,
      updateTime: null,
      remark: null,
      poi: null,
      delFlag: null,
      params: {},
      id: 15,
      typeName: '综合执法',
      originalType: '市容秩序类',
      platform: 'szhcg',
      status: '0',
    },
    {
      searchValue: null,
      gridId: null,
      gridName: null,
      gridDept: null,
      gridIds: null,
      gridIdsString: null,
      createBy: null,
      createTime: '2024-02-27 15:22:18',
      updateBy: null,
      updateTime: null,
      remark: null,
      poi: null,
      delFlag: null,
      params: {},
      id: 16,
      typeName: '综合执法',
      originalType: '违法建设类',
      platform: 'szhcg',
      status: '0',
    },
    {
      searchValue: null,
      gridId: null,
      gridName: null,
      gridDept: null,
      gridIds: null,
      gridIdsString: null,
      createBy: null,
      createTime: '2024-02-27 15:22:18',
      updateBy: null,
      updateTime: null,
      remark: null,
      poi: null,
      delFlag: null,
      params: {},
      id: 17,
      typeName: '综合执法',
      originalType: '园林绿化类',
      platform: 'szhcg',
      status: '0',
    },
  ]);
  const queryParams = ref({
    pageNum: 1,
    pageSize: 10,
    typeName: null,
    originalType: null,
    platform: null,
    status: null,
  });
  const form = ref({});
</script>

<style lang="scss" scoped>
  .app-container {
    box-sizing: border-box;
    padding: 20px;
    overflow: auto;
  }
  .mb8 {
    margin-bottom: 8px;
  }
</style>
